<?php

namespace App\Listeners\Comment;

use App\Common\Libs\Dispatch\Queue;
use App\Consts\GlobalQueueConst;
use App\Events\DelCommentEvent;
use App\Jobs\Controller\MessageJob;
use App\Listeners\BaseListener;

class DelCommentListener extends BaseListener
{
    /**
     * Handle the event.
     *
     * @param DelCommentEvent $event
     * @return bool
     */
    public function handle(DelCommentEvent $event)
    {
        $this->saveFileLog(__CLASS__, $event);

        $comment = $event->comment;

        // 队列记录日志
        service()->LogCountService->createLogByQueue($event->logCountLoadData);

        /**
         * 队列删除：
         *  1. 该评论的：【我发出的评论】【我收到的评论】【我发出的赞】【我收到的赞】
         *  2. 回复该评论的所有回复：【我发出的评论】【我收到的评论】【我发出的赞】【我收到的赞】
         */
        Queue::getInstance(MessageJob::class)
            ->push([
                'comment_id' => $comment['comment_id']
            ], GlobalQueueConst::MESSAGE_DEL_COMMENT);

        return true;
    }
}
